package com.hq.talk.service;

import android.app.IntentService;
import android.content.Intent;
import android.os.CountDownTimer;

public class BackGroundService extends IntentService {

    /**
     * 验证码时间
     */
    public static long time_code = 0;

    public static MyCountCode countCode;

    public BackGroundService() {
        super("BackGroundService");
    }

    @Override
    protected void onHandleIntent(Intent data) {
    }

    /**
     * 倒计时类
     */
    public static class MyCountCode extends CountDownTimer {

        public MyCountCode(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        @Override
        public void onTick(long millisUntilFinished) {
            time_code = millisUntilFinished;
        }

        @Override
        public void onFinish() {
            time_code = 0;
        }
    }

    /**
     * 倒计时
     *
     * @param time
     * @return
     */
    public static void countDownCode(long time) {
        if (null != countCode) {
            countCode.cancel();
            countCode = null;
        }
        countCode = new MyCountCode(time, 1000);
        countCode.start();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        if (null != countCode) {
            countCode.cancel();
        }
    }
}
